package club.monkeywood.ad.dmp.util

import org.apache.spark.sql.Row

import scala.collection.mutable.ListBuffer

object TagsUtils {

    //过滤掉没有用户id的数据
    val hasSomeUserIdConditition =
        """
          | imei != "" or imeimd5 != "" or imeisha1 != "" or
          | idfa != "" or idfamd5 != "" or idfasha1 != "" or
          | mac != "" or macmd5 != "" or macsha1 != "" or
          | androidid != "" or androididmd5 != "" or androididsha1 != "" or
          | openudid != "" or openudidmd5 != "" or openudidsha1 != ""
        """.stripMargin


    //查询经纬度在中国区，且有用户id的数据
    val testCdt =
        """
          | (imei != "" or imeimd5 != "" or imeisha1 != "" or
          | idfa != "" or idfamd5 != "" or idfasha1 != "" or
          | mac != "" or macmd5 != "" or macsha1 != "" or
          | androidid != "" or androididmd5 != "" or androididsha1 != "" or
          | openudid != "" or openudidmd5 != "" or openudidsha1 != "") and
          | lat > 3 and lat < 54 and log > 73 and log < 136
        """.stripMargin




    //获取用户id数组
    //由于用户信息来源与不同平台，辨识用户的id不止一种
    def getAllUserId(v: Row): ListBuffer[String] = {

        val userIds = new collection.mutable.ListBuffer[String]()

        if(v.getAs[String]("imei").nonEmpty ) userIds.append("IM:"+v.getAs[String]("imei").toUpperCase)
        if(v.getAs[String]("idfa").nonEmpty ) userIds.append("DF:"+v.getAs[String]("idfa").toUpperCase)
        if(v.getAs[String]("mac").nonEmpty ) userIds.append("MC:"+v.getAs[String]("mac").toUpperCase)
        if(v.getAs[String]("androidid").nonEmpty ) userIds.append("AD:"+v.getAs[String]("androidid").toUpperCase)
        if(v.getAs[String]("openudid").nonEmpty ) userIds.append("OU:"+v.getAs[String]("openudid").toUpperCase)
        if(v.getAs[String]("imeimd5").nonEmpty ) userIds.append("IMM:"+v.getAs[String]("imeimd5").toUpperCase)
        if(v.getAs[String]("idfamd5").nonEmpty ) userIds.append("DFM:"+v.getAs[String]("idfamd5").toUpperCase)
        if(v.getAs[String]("macmd5").nonEmpty ) userIds.append("MCM:"+v.getAs[String]("macmd5").toUpperCase)
        if(v.getAs[String]("androididmd5").nonEmpty ) userIds.append("ADM:"+v.getAs[String]("androididmd5").toUpperCase)
        if(v.getAs[String]("openudidmd5").nonEmpty ) userIds.append("OUM:"+v.getAs[String]("openudidmd5").toUpperCase)
        if(v.getAs[String]("imeisha1").nonEmpty ) userIds.append("IMS:"+v.getAs[String]("imeisha1").toUpperCase)
        if(v.getAs[String]("idfasha1").nonEmpty ) userIds.append("DFS:"+v.getAs[String]("idfasha1").toUpperCase)
        if(v.getAs[String]("macsha1").nonEmpty ) userIds.append("MCS:"+v.getAs[String]("macsha1").toUpperCase)
        if(v.getAs[String]("androididsha1").nonEmpty ) userIds.append("ADS:"+v.getAs[String]("androididsha1").toUpperCase)
        if(v.getAs[String]("openudidsha1").nonEmpty ) userIds.append("OUS:"+v.getAs[String]("openudidsha1").toUpperCase)


        userIds
    }

}
